FROM ubuntu:20.04

# 避免交互式安装
ENV DEBIAN_FRONTEND=noninteractive

# 安装基础工具和编译环境
RUN apt-get update && apt-get install -y \
    build-essential \
    cmake \
    git \
    wget \
    curl \
    pkg-config \
    libgtk-3-dev \
    libavcodec-dev \
    libavformat-dev \
    libswscale-dev \
    libv4l-dev \
    libxvidcore-dev \
    libx264-dev \
    libjpeg-dev \
    libpng-dev \
    libtiff-dev \
    libatlas-base-dev \
    gfortran \
    libgomp1 \
    && rm -rf /var/lib/apt/lists/*

# 安装 OpenCV
RUN cd /tmp && \
    wget -O opencv.zip https://github.com/opencv/opencv/archive/4.8.1.zip && \
    wget -O opencv_contrib.zip https://github.com/opencv/opencv_contrib/archive/4.8.1.zip && \
    unzip opencv.zip && \
    unzip opencv_contrib.zip && \
    cd opencv-4.8.1 && \
    mkdir build && cd build && \
    cmake -D CMAKE_BUILD_TYPE=RELEASE \
          -D CMAKE_INSTALL_PREFIX=/usr/local \
          -D INSTALL_PYTHON_EXAMPLES=OFF \
          -D INSTALL_C_EXAMPLES=OFF \
          -D OPENCV_ENABLE_NONFREE=ON \
          -D OPENCV_EXTRA_MODULES_PATH=/tmp/opencv_contrib-4.8.1/modules \
          -D PYTHON_EXECUTABLE=$(which python3) \
          -D BUILD_EXAMPLES=OFF \
          -D WITH_CUDA=OFF \
          -D WITH_OPENCL=OFF \
          -D WITH_IPP=OFF \
          -D WITH_TBB=ON \
          -D WITH_OPENMP=ON \
          .. && \
    make -j$(nproc) && \
    make install && \
    ldconfig && \
    cd /tmp && \
    rm -rf opencv-4.8.1 opencv_contrib-4.8.1 opencv.zip opencv_contrib.zip

# 安装 nlohmann/json
RUN cd /tmp && \
    wget https://github.com/nlohmann/json/releases/download/v3.11.2/json.tar.xz && \
    tar -xf json.tar.xz && \
    cd json && \
    mkdir build && cd build && \
    cmake .. && \
    make -j$(nproc) && \
    make install && \
    cd /tmp && \
    rm -rf json json.tar.xz

# 安装 cpp-httplib
RUN cd /tmp && \
    wget https://github.com/yhirose/cpp-httplib/archive/refs/tags/v0.14.1.tar.gz && \
    tar -xf v0.14.1.tar.gz && \
    cd cpp-httplib-0.14.1 && \
    mkdir build && cd build && \
    cmake .. && \
    make -j$(nproc) && \
    make install && \
    cd /tmp && \
    rm -rf cpp-httplib-0.14.1 v0.14.1.tar.gz

# 设置工作目录
WORKDIR /app

# 复制源代码
COPY . .

# 创建构建目录并编译
RUN mkdir build && cd build && \
    cmake .. && \
    make -j$(nproc) && \
    make install

# 暴露端口
EXPOSE 8000

# 启动命令
CMD ["./build/reconstruction_service"] 